<?php
/*
Template Name: daily
*/
get_header();
?>
    <div class="container">
        <div class="row-fluid">
            <div class="span9">
                    <div>
                        <?php 
                        if(!defined("DAILY_NOPOST"))
                        {
                            echo "<h2>". get_the_title() . "</h2>";
                            echo "<span><i class='icon-calendar'></i>  ".get_the_date("Y年m月d日")."</span> | <i class='icon-tags'></i>  ";
                            the_tags(""," • ","");
                        ?>
                            | <i class="icon-comment"></i> <?php comments_popup_link( '<span class="leave-reply">发表评论</span>', "1 条评论", "% 条评论"); ?>
                        <?php
                            $day = get_the_date("Ymd");
                        ?>
                        <div class="entry-content">
                        <?php the_content(); ?>
                        </div><!-- .entry-content -->
                        <p><a id='showanswer' href='javascript:void(0);' class='btn btn-primary btn-large'>显示参考</a></p>
                        <?php 
                        wp_reset_postdata();
                        }
                        else
                        {
                            echo "<h1>".UNKNOWN_POST."</h1>";
                            $day=$_GET["d"];
                        }
                        ?>
                    </div>
                    <hr>
                    <div>
                        <h3>本月文章</h3>
                        <div>
                            <table class="table table-condensed">
                              <thead>
                                <tr>
                                  <th>日期</th>
                                  <th>文章</th>
                                  <th>标签</th>
                                </tr>
                              </thead>
                              <tbody>
                                <?php
                                $monthargs = array(
                                    'category_name'  => 'daily',
                                    'posts_per_page'  => 31,
                                    'offset'          => 0,
                                    'orderby'         => 'post_date',
                                    'order'           => 'DESC',
                                    'year'            => substr($day,0,4),
                                    'monthnum'        => substr($day,4,2)
                                    );
                                $query = new WP_Query( $monthargs );

                                //The Loop
                                while ( $query->have_posts() ) 
                                {
                                    $query->the_post();
                                    echo "<tr>";
                                    echo "<td>".get_the_date("d")."</td>";
                                    echo "<td><a href='/daily/?d=".get_the_date("Ymd")."'>".get_the_title()."</a></td>";
                                    the_tags("<td ><span class='tags'>"," ","</span></td>");
                                    echo "</tr>";
                                }
                                wp_reset_postdata();
                                ?>
                              </tbody>
                            </table>
                        </div>
                    </div>
            </div><!--/span-->
            <div class="span3 well">
                <h4><i class="icon-calendar"></i> 日历</h4>
                <div id="datetimepicker"></div>
                <hr>        
                <?php get_sidebar(); ?>
            </div><!--/span-->
      </div><!--/row-->
      
      </div> <!-- /container-fluid -->
      <script>      
            $(function(){
                $('#datetimepicker').datetimepicker(
                {
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    minView: 'month',
                    todayBtn: 'linked',
                    startDate: '<?php echo substr(DAILY_START,0,4)."-".substr(DAILY_START,4,2)."-".substr(DAILY_START,6,2); ?>',
                    initialDate: '<?php echo substr($day,0,4)."-".substr($day,4,2)."-".substr($day,6,2); ?>'
                }).on('changeDate', function(ev){
                    var year=1900+ev.date.getYear();
                    var month=ev.date.getUTCMonth()+1;
                    var day=ev.date.getUTCDate();
                    if(month<10)
                        month="0"+month;
                    if(day<10)
                        day="0"+day;
                    window.location.href="/daily/?d="+year+month+day; 
                });
                $('#showanswer').click(function(){
                    if($("#showanswer").attr("answer-display")=="yes")
                    {  
                        $('.dailyanswer').fadeOut();
                        $("#showanswer").removeAttr("answer-display");
                        $('#showanswer').html("显示参考");
                    }
                    else
                    {  
                        $('.dailyanswer').fadeIn();
                        $("#showanswer").attr("answer-display","yes");
                        $('#showanswer').html("隐藏参考");
                    }
                });
                $('.tags > a').addClass("btn btn-success");
            });
      </script>
<?php
get_footer();
?>
